home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-15 | 4.9 KB | 237 lines | [TEXT/ALFA] |
- # FILE: compare-windows.tcl
- #
- # LAST UPDATE: 01/06/93 5:24:32 AM
- #
- # This file contains the following TCL procedure(s):
- #
- # compare-windows -- Compare two windows from the cursor and position
- # the cursors at the next difference
- #
- # TCL SYNTAX:
- #
- # NOTE: The options are not yet fully functional
- #
- # compare-windows [-w|-b] [-c] [file1] [file2]
- #
- # -b ignore blanks and tabs
- # -w ignore blacks, tabs, newlines, returns
- # -c case insenstive (ie. A matches a)
- #
- # To use, simply source this file place it in the a folder with the
- # name $HOME:Tcl:Usercode: and invoke it implicitly via the "unknown proc".
- #
- # SEE ALSO unknown.tcl
-
- # COPYRIGHT:
- #
- # Copyright ゥ 1992,1993 by David C. Black
- # All rights reserved.
- #
- # Redistribution and use in source and binary forms are permitted
- # provided that the above copyright notice and this paragraph are
- # duplicated in all such forms and that any documentation,
- # advertising materials, and other materials related to such
- # distribution and use acknowledge that the software was developed
- # by David C. Black.
- #
- # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
- # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- #
- ################################################################################
-
- # AUTHOR
- #
- # David C. Black
- # Internet: black@mpd.tandem.com (preferred)
- # GEnie: D.C.Black
- # USnail: 6217 John Chisum Lane, Austin, TX 78749
- #
- ################################################################################
-
- # HISTORY
- #
- # modified who rev reason
- # -------- --- --- ------
- # 01/06/93 DCB 1.0 Original
-
- proc compare-windows {args} {
-
- set patt {}
- set fold 0
- set wins [winNames]
- # set wins [winNames -f]
- set files {}
- if {[llength $args] > 0} {
- foreach arg $args {
- case $arg {
- {-c} {
- set fold 1
- }
- {-b} {
- set patt "¥[ ¥t¥]+"
- }
- {-w} {
- set patt "¥[ ¥t¥n¥r¥]+"
- }
- {} {
- }
- default {
- if {[string first ":" $arg] < 0} {
- set arg "[pwd]$arg"
- }
- set found 0
- foreach win $wins {
- if {$arg == $win} {
- set found 1
- break
- }
- }
- if {$found} {
- lappend files $arg
- } else {
- if {[file exists $arg]} {
- lappend files $arg
- edit $arg -r
- } else {
- alertnote "Cannot read $arg"
- }
- }
- }
- }
- }
- }
- set files [concat $files $wins]
-
- if {[llength $files] < 2} {
- alertnote "Need at least 2 windows/files"
- return
- }
-
- # Get window 1 text to compare
- set wn(1) [lindex $files 0]
- bringToFront $wn(1)
- if {[getSelect] != ""} {
- forwardChar
- }
- set wp(1) [getPos]
- set wo(1) [getText $wp(1) [maxPos]]
- set wt(1) $wo(1)
- if {$patt != ""} {
- regsub -all $patt $wt(1) " " wt(1)
- }
- if {$fold} {
- set wt(1) [string tolower $wt(1)]
- }
-
- # Get window 2 text to compare
- set wn(2) [lindex $files 1]
- bringToFront $wn(2)
- if {[getSelect] != ""} {
- forwardChar
- }
- set wp(2) [getPos]
- set wo(2) [getText $wp(2) [maxPos]]
- set wt(2) $wo(2)
- if {$patt != ""} {
- regsub -all $patt $wt(2) " " wt(2)
- }
-
- # Exactly equal
- if {$wt(1) == $wt(2)} {
- message "Identical"
- return
- }
-
- # Only consider smaller of two strings
- set siz [string length $wt(1)]
- if {$siz > [string length $wt(2)]} {
- set siz [string length $wt(2)]
- }
-
- # Equal except for added stuff
- set l [expr {$siz-1}]
- if {[string range $wt(1) 0 $l] == [string range $wt(2) 0 $l]} {
- set beg $siz
- set offset(1) $beg
- set offset(2) $beg
- } else {
- set beg 0
- set trace {}
-
- while {$siz} {
- set siz [expr {$siz / 2}]
- set end [expr {$beg+$siz}]
- if {[string range $wt(1) $beg $end] == [string range $wt(2) $beg $end]} {
- incr beg $siz
- incr beg
- }
- }
-
- set offset(1) $beg
- set offset(2) $beg
-
- # adjust for $patt
- if {$patt != ""} {
- foreach i {1 2} {
- set front ""
- set left [expr {$beg+1}]
- set back $wo($i)
- set iterations 0
- while {$left > 0} {
- append front [string range $back 0 [expr {$left-1}]]
- set back [string range $back $left end]
- regsub -all $patt $front { } front
- set left [expr {$beg + 1 - [string length $front]}]
- incr offset($i) $left
- if {[incr iterations] > 100} {
- alertnote "diff: iterations exceeded 100"
- break
- }
- #BEG DEBUG
- global testing
- if {$testing} {
- set o $offset($i)
- regsub -all "¥[¥r¥n¥]*" $front "・" t
- if {[getline "$iヌ$tネ $left/$o" "continue"] != "continue"} {
- break
- }
- }
- #END DEBUG
- }
- }
-
- }
- }
-
-
- # bringToFront $wn(2)
- set pos [expr {$wp(2)+$offset(2)}]
- if {$pos > [maxPos]} {
- goto end
- } else {
- goto $pos
- }
- centerRedraw
- forwardCharSelect
-
- bringToFront $wn(1)
- # listpick $trace
- set pos [expr {$wp(1)+$offset(1)}]
- if {$pos > [maxPos]} {
- goto end
- } else {
- goto $pos
- }
- centerRedraw
- forwardCharSelect
-
- return
- }
-
- set testing 0
- if {$testing} {
- set cwd [pwd]
- diff -b "${cwd}TCLs:1.txt" "${cwd}TCLs:2.txt"
- }
-